﻿/*
 * IServiceSelector
 * 
 * Select a service
 * 
 * Author: snowdreamist
 * Date: 2011/12/7
 * 
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BitTorrentSharp.KRPC.Messages;

namespace BitTorrentSharp.KRPC.Handler
{
    public interface IServiceSelector
    {
        KRPCService Select(MessageContext context);
    }

    public class DefaultServiceSelector : IServiceSelector
    {
        public KRPCService Select(MessageContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (context.Host.Services.Count < 1)
                throw new KRPCException("No service avaliable");
            if (context.Host.Services.Count > 1)
                throw new KRPCException("Only one service is supported");
            return context.Host.Services[0];
        }
    }
}
